<template>
  <div>
    <div v-html="html" v-if="!url"></div>
    <pdf v-else :src="url" v-for="i in numPages" :key="i" :page="i" class="pdf-mid-class"></pdf>
  </div>
</template>
<script>
import pdf from 'vue-pdf'
export default {
  name: 'association',
  data () {
    return {
      html: '',
      url: '',
      numPages: null
    }
  },
  components: {
    pdf
  },
  computed: {
  },
  created () {
    this.getNewTitles()
  },
  methods: {
    getNewTitles () {
      this.$http.showArticle({}, 100014).then(res => {
        if (res.data && res.data.length && res.data[0].realPath) {
          this.url = `${process.env.VUE_APP_SRC}${res.data[0].realPath}`
          this.getNumPages()
        } else {
          this.html = res.data[0].content
        }
      })
    },
    getNumPages () {
      let loadingTask = pdf.createLoadingTask(this.url)
      loadingTask.promise.then(pdf => {
        this.numPages = pdf.numPages
      }).catch(err => {
        console.error('pdf 加载失败', err)
      })
    }
  }
}
</script>
<style lang="scss">
</style>
